package com.ict.web.dto;

import com.ict.common.annotation.Excel;
import com.ict.common.core.domain.model.LoginUser;
import com.ict.common.utils.SecurityUtils;
import com.ict.common.utils.bean.BeanUtils;
import com.ict.common.utils.uuid.IdUtils;
import com.ict.web.constant.ProjectStatusEnum;
import com.ict.web.domain.ProjectManagement;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@Data
public class ProjectManagementAddDto {

    /** 项目名称 */
    @Excel(name = "项目名称")
    private String name;

    /** 项目性质:{0:年度项目;1:增补项目;} */
    @Excel(name = "项目性质:{0:年度项目;1:增补项目;}")
    private String nature;

    /** 项目类别:{0:建设类;1:购买服务类;} */
    @Excel(name = "项目类别:{0:建设类;1:购买服务类;}")
    private String type;

    /** 投资估算 */
    @Excel(name = "投资估算")
    private BigDecimal investmentEstimation;

    /** 阶段：{0:项目申报  1:方案申报  2:项目实施  3:项目验收} */
    @ApiModelProperty(value = "阶段：{0:项目申报  1:方案申报  2:项目实施  3:项目验收}")
    @Excel(name = "阶段")
    private String stag;

    /** 节点 */
    @Excel(name = "节点")
    private String node;

    /** 状态：{0:已提交;1:待审核;2:通过;3:退回修改;4:驳回;……} */
    @Excel(name = "状态：{0:已提交;1:待审核;2:通过;3:退回修改;4:驳回;……}")
    private String isState;

    /** 评审意见 */
    @Excel(name = "评审意见")
    private String reviewComments;

    /** 年度项目计划id */
    @Excel(name = "年度项目计划id")
    private Long planId;

    /** 年度申报id */
    @Excel(name = "年度申报id")
    private Long annualId;

    /** 增补申报id */
    @Excel(name = "增补申报id")
    private Long supplementaryId;

    /** 方案申报id */
    @Excel(name = "方案申报id")
    private Long programmeId;

    /** 合同id */
    @Excel(name = "合同id")
    private Long contractId;

    /** 里程碑id */
    @Excel(name = "里程碑id")
    private Long milepostId;

    /** 发改/财政审批备案id */
    @Excel(name = "发改/财政审批备案id")
    private Long financeId;

    /** 初验备案id */
    @Excel(name = "初验备案id")
    private Long firstCheckId;

    /** 合规id */
    @Excel(name = "合规id")
    private Long complianceId;

    /** 终验备案id */
    @Excel(name = "终验备案id")
    private Long lastCheckId;

    /** 三方id */
    @Excel(name = "三方id")
    private Long tripartiteId;

    /** 绩效id */
    @Excel(name = "绩效id")
    private Long perId;

    /** 项目建议书（文件id） */
    private String projectProposal;

    /**
     * 将 ProjectManagementAddDto 转化为 ProjectManagement
     *
     * @param dto 接收dto
     * @return HotelInfo
     */
    public static ProjectManagement of(ProjectManagementAddDto dto){
        ProjectManagement bean = new ProjectManagement();
        BeanUtils.copyProperties(dto,bean);

        //设置ID
        bean.setProId(IdUtils.snowId());
        //设置创建时间
        bean.setCreateTime(LocalDateTime.now());
        //设置创建时间
        bean.setUpdateTime(LocalDateTime.now());
        //设置物理删除标记
        bean.setIsDelete("0");
        //设置操作人id和操作人昵称
        LoginUser loginUser = SecurityUtils.getLoginUser();
        bean.setUserId(loginUser.getUserId());
        bean.setNickName(loginUser.getUser().getNickName());
        //设置阶段 默认为 项目申报
        //如果是增补申报则阶段为项目审批
        if ("1".equals(bean.getNature())){
            if ("1".equals(bean.getIsState())){
                //已提交
                bean.setStag(ProjectStatusEnum.APPLICATION_REVIEW_TO_BE_REVIEWED.get().getStage());
                bean.setIsState(ProjectStatusEnum.APPLICATION_REVIEW_TO_BE_REVIEWED.get().getStatus());
                bean.setNode(ProjectStatusEnum.APPLICATION_REVIEW_TO_BE_REVIEWED.get().getNode());
            }else{
                //未提交
                bean.setStag(ProjectStatusEnum.STATEMENT_NOT_SUBMITTED.get().getStage());
                bean.setIsState(ProjectStatusEnum.STATEMENT_NOT_SUBMITTED.get().getStatus());
                bean.setNode(ProjectStatusEnum.STATEMENT_NOT_SUBMITTED.get().getNode());
            }

        }else{
            if ("0".equals(bean.getIsState())){
                //已提交
                bean.setStag(ProjectStatusEnum.DECLARATION_SUBMISSION_SUBMITTED.get().getStage());
                bean.setIsState(ProjectStatusEnum.DECLARATION_SUBMISSION_SUBMITTED.get().getStatus());
                bean.setNode(ProjectStatusEnum.DECLARATION_SUBMISSION_SUBMITTED.get().getNode());
            }else if("-1".equals(bean.getIsState())){
                //未提交
                bean.setStag(ProjectStatusEnum.STATEMENT_NOT_SUBMITTED.get().getStage());
                bean.setIsState(ProjectStatusEnum.STATEMENT_NOT_SUBMITTED.get().getStatus());
                bean.setNode(ProjectStatusEnum.STATEMENT_NOT_SUBMITTED.get().getNode());
            }else  if("1".equals(bean.getIsState())){
                bean.setStag(ProjectStatusEnum.APPLICATION_REVIEW_TO_BE_REVIEWED.get().getStage());
                bean.setIsState(ProjectStatusEnum.APPLICATION_REVIEW_TO_BE_REVIEWED.get().getStatus());
                bean.setNode(ProjectStatusEnum.APPLICATION_REVIEW_TO_BE_REVIEWED.get().getNode());
            }

        }
        return bean;
    }
}
